/**
* AutoSWF - Cody Cushing. March 26, 2009
* Copyright (c) 2009 Cody Cushing
* No use restrictions. Maintain this notice in all versions. 
**/

package com.autoswf.taskrunner
{
	import flexunit.framework.TestCase;

	public class TaskRunnerTest extends TestCase
	{
		private var taskFactory:MockTaskFactory;
		private var taskRunner:TaskRunner;
		
		public function TaskRunnerTest(methodName:String=null)
		{
			super(methodName);
		}
		
		override public function setUp():void
		{
			taskFactory = new MockTaskFactory();
			taskRunner = new TaskRunner(taskFactory);
		}
		
		/**
		 * Tests that a new task is started if there is not a completed task for that id. 
		 */		
		public function testLoaderModel01():void
		{
			var request:MockRequest = new MockRequest();
			request.mock.property("id").andReturn("testId").once;
			request.mock.property("data").withArgs("dataVal").twice;
			
			
			var taskMock:MockTask = new MockTask();
			taskMock.mock.method("run").once.ordered();
			taskMock.mock.property("id").andReturn("testId").once.ordered();
			taskMock.mock.property("result").andReturn("").once.ordered();
			taskMock.mock.property("id").andReturn("testId").once.ordered();
			
			taskFactory.mock.method("getTask").withArgs(request).andReturn(taskMock);
			
			taskRunner.addTask(request);	
			taskMock.dispatchEvent(new TaskEvent(TaskEvent.TASK_COMPLETE, "testId"));
			
			assertTrue(taskFactory.mock.verify() && taskMock.mock.verify());
		}
	}
}